package com.fx.common;

import java.util.function.Consumer;
import java.util.function.Supplier;

public abstract class AbsButtonController<T> implements ButtonController, Consumer<T> {

    protected Supplier<T> createSource;

    public AbsButtonController(Supplier<T> createSource){
        this.createSource = createSource;
    }

    protected T source(){
       return createSource.get();
    }

    protected Supplier<Boolean> supplier;

    @Override
    public void perform(){
        this.accept(source());
    }

    @Override
    public boolean canClick() {
        if(supplier == null){
            return true;
        }
        return supplier.get();
    }

    protected void setCan(Supplier<Boolean> supplier){
        this.supplier = supplier;
    }
}
